package com.yanqu.road.logic.activity.foxcard.game.sorcery;

import com.yanqu.road.entity.activity.foxcard.FoxConsumeCard;
import com.yanqu.road.entity.activity.foxcard.config.FoxCardSorceryConfig;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardGameLogic;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardType;

import java.util.Collections;
import java.util.List;

public class FoxCardSorceryUseBase implements FoxCardSorceryUse{
    protected FoxCardSorceryConfig sorceryConfig;
    protected FoxConsumeCard consumeCard;
    protected List<Integer> targetIdList;
    @Override
    public FoxCardSorceryUse init(FoxCardSorceryConfig config, List<Integer> targetIdList, FoxConsumeCard consumeCard) {
        this.sorceryConfig = config;
        this.consumeCard = consumeCard;
        this.targetIdList = targetIdList;
        return this;
    }

    protected boolean sorceryUse(FoxCardGameLogic gameLogic) {
        return true;
    }

    @Override
    public boolean use(FoxCardGameLogic gameLogic) {
        boolean ret = sorceryUse(gameLogic);
        if (ret) {
            if (consumeCard != null) {
                gameLogic.destroyConsumeCards(Collections.singletonList(consumeCard));
            }
            Integer times = gameLogic.getGameData().getConsumeCardTimesMap().getOrDefault(eFoxCardType.SORCERY.getValue(), 0);
            gameLogic.getGameData().getConsumeCardTimesMap().put(eFoxCardType.SORCERY.getValue(), times + 1);
            gameLogic.setLastUseConsumeType(eFoxCardType.SORCERY.getValue());
        }
        return ret;
    }
}
